package com.eudon.user.controller;

import com.eudon.user.domain.req.RegisterReq;
import com.eudon.user.domain.resp.BaseResp;
import com.eudon.user.domain.resp.RegisterResp;
import com.eudon.user.enums.RespCode;
import com.eudon.user.exception.BusinessException;
import com.eudon.user.service.UserRegisterService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author eudon
 * @description 用户相关操作控制器层
 * @date 2025/9/8
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserRegisterService registerService;

    @PostMapping("/register")
    public BaseResp<RegisterResp> register(@Valid @RequestBody RegisterReq registerReq) {
        if (registerReq == null) {
            throw new BusinessException(RespCode.PARAMS_ERROR);
        }
        Long userId = registerService.register(registerReq);
        return BaseResp.ofSuccess(new RegisterResp(registerReq.getUserName(), userId));
    }
}
